﻿@using zichan.Entity
@model IPagedList<Menu>
@{
    ViewBag.Title = "菜单管理";
}

@section Pagetitle{
    @AdminCommon.PageTitle("菜单管理", "添加&删除")
}


@section header{
    <style type="text/css">
        .tree .tree-item .icon-file {
            width: 14px;
        }

        .tree .tree-item {
            height: auto;
            padding: 0px;
        }

            .tree .tree-item:hover {
                background-color: white;
            }

        .tree .tree-item, .tree .tree-folder {
            border: 0px solid #FFF;
        }

        .tree a {
            text-decoration: none;
            display: inline-block !important;
        }

        .tree .tool {
            padding-left: 10px;
            visibility: hidden;
        }

        .tree .le {
            padding: 5px;
        }

        .le:hover {
        }

            .le:hover .tool {
                visibility: visible;
            }

        .level0 .til {
            font-weight: bold;
        }
    </style>
}

@helper MeunItem(Menu m, bool InChild, bool open)
{
    <div class="level@(m.Level) le" id="nut(@m.Id)">
        <i class="@(InChild ? "icon blue fa " + (open ? "fa-folder-open" : "fa-folder") : "fa fa-file blue")"></i> <span class="til">@m.Title</span>
        <span class="tool ">
            <a href="@Url.Action("edit", new { id = m.Id})"><i class="icon-edit "></i> 编辑</a>
            @if (m.Level < 2)
            {
                <a href="@Url.Action("Create", new { id = m.Id })"><i class="icon-plus-sign "></i> 添加子菜单</a>
            }
            <a href="@Url.Action("delete", new { id = m.Id })"><i class="icon-trash "></i> 删除</a>
        </span>
    </div>
}


<div class="portlet">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-table"></i>菜单列表
        </div>
        <div class="actions">
            @if (zichan.Common.PowerHelp.Check("menu", "create"))
            {
                <a target="_self" href="@Url.Action("create","menu")" class="btn btn-sm default  yellow-stripe">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-480">添加菜单</span>
                </a>
            }
        </div>
    </div>
    <div class="portlet-body">
        <div class="table-container">

            <div class="dataTables_wrapper dataTables_extended_wrapper no-footer">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-group-actions pull-right">
                            @using (Html.BeginForm("index", "menu", FormMethod.Get))
                            {
                                <div class="input-group">
                                    <input type="text" placeholder="菜单名称" name="name" value="@ViewBag.name" class="table-group-action-input form-control input-inline input-small input-sm" />
                                    <input type="text" placeholder="Controller" name="cller" value="@ViewBag.cller" class="table-group-action-input form-control input-inline input-small input-sm" />
                                    <input type="text" placeholder="Action" name="act" value="@ViewBag.act" class="table-group-action-input form-control input-inline input-small input-sm" />
                                    <button class="btn btn-sm yellow table-group-action-submit"><i class="fa fa-check"></i> 搜索</button>
                                </div>
                            }
                        </div>
                    </div>
                </div>
                <div class="table-scrollable">
                    <div class="tree">
                        @{
                            var topms1 = Model.Where(o => o.Level == 0).OrderBy(o => o.Sort);
                            foreach (var tm in topms1)
                            {
                                var topms2 = Model.Where(o => o.Path.Contains("," + tm.Id + ",") && o.Level == 1).OrderBy(o => o.Sort).ToList();
                                bool istm = topms2.Count() > 0;
                                <div class="tree-item">
                                    @MeunItem(tm, istm, true)
                                    @if (istm)
                                    {
                                        <div class="tree" style="margin-left:25px;">
                                            @foreach (var tm2 in topms2)
                                            {
                                                var topms3 = Model.Where(o => o.Path.Contains("," + tm2.Id + ",") && o.Level == 2).OrderBy(o => o.Sort).ToList();
                                                bool istm2 = topms3.Count() > 0;
                                                <div class="tree-item">
                                                    @MeunItem(tm2, istm2, false)
                                                    @if (istm2)
                                                    {
                                                        <div class="tree" style="margin-left: 25px;">
                                                            @foreach (var tm3 in topms3)
                                                            {
                                                                <div class="tree-item">@MeunItem(tm3, true, false)</div>
                                                            }
                                                        </div>
                                                    }
                                                </div>
                                            }
                                        </div>
                                    }
                                </div>
                            }
                        }
                    </div>
                </div>


            </div>

        </div>
    </div>
</div>








@section footer{
    <script type="text/javascript">
            $(function () {
                $(".icon").on("click", function () {

                    $(this).toggleClass("fa-folder-open").toggleClass("fa-folder").parent().next("div").toggleClass("hide");
                })
            });
    </script>
}







